/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package rosedb.model;

import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

/**
 *
 * @author riu
 */
public abstract class SearchComparators {

    public static class AlphabeticRoseComparator implements Comparator<Rose>{

        @Override
        public int compare(Rose o1, Rose o2) {
            return o1.getName().toLowerCase().compareTo(o2.getName().toLowerCase());
        }

    }
    
    
    public static class NameRoseComparator implements Comparator<Rose>{

        private String name;

        public NameRoseComparator(String name) {
            this.name = name.toLowerCase();
        }
        
        
        @Override
        public int compare(Rose o1, Rose o2) {
            String name1 = o1.getName().toLowerCase();
            String name2 = o2.getName().toLowerCase();


            if(name1.contains(name) && !name2.contains(name)){
                return -1;
            }else if(name2.contains(name) && !name1.contains(name)){
                return 1;
            }else if(name1.contains(name) && name2.contains(name)){
                if(name1.startsWith(name) && !name2.startsWith(name)){
                    return -1;
                }
                if(!name1.startsWith(name) && name2.startsWith(name)){
                    return 1;
                }
                if(name1.startsWith(name) && name2.startsWith(name)){
                    return name1.compareTo(name2);
                }
            }

            
            return name1.compareTo(name2);
            
        }

    }
    
    
    public static class FeatureRoseComparator implements Comparator<Rose>{

        private Map<String, String> features = new TreeMap<String, String>();

        public FeatureRoseComparator(String featName, String featValue) {
            features.put(featName, featValue);
        }

        public FeatureRoseComparator(Map<String, String> f) {
            features = f;
        }


        @Override
        public int compare(Rose o1, Rose o2) {
            return o1.getName().compareTo(o2.getName());
        }

    }


}
